package org.scirp.ijmis.dao.common.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.scirp.ijmis.dao.base.impl.BaseDAOImpl;
import org.scirp.ijmis.dao.common.ISurveyDAO;
import org.scirp.ijmis.po.common.Survey;
import org.scirp.ijmis.po.personpaper.Login;
import org.scirp.ijmis.po.personpaper.Paper;

public class SurveyDAOImpl extends BaseDAOImpl<Survey> implements ISurveyDAO {

	private static final String className = SurveyDAOImpl.class.toString();

	public List<Survey> selectAll() {
		String hql = "from Survey order by pid desc";
		return super.ExecuteQuery(hql, className + "-->selectAll");
	}
	public List<Survey> selectDisplayAll() {
		String hql = "from Survey where display='true' order by pid desc";
		return super.ExecuteQuery(hql, className + "-->selectAll");
	}
	public Survey selectById(Object id) {
		return (Survey) super.selectById(id, className + "-->selectById");
	}
	public List<Survey> selectByPersonId(Long personId){
		String hql="from  Survey where pid not in(select survey.pid from SurveyChoice where pid in(select surveyChoice.pid from SurveyChoiceOfPerson where personid=:personId))";
		Map<String, Long> parameters = new HashMap<String, Long>();
		parameters.put("personId", personId);
		return super.ExecuteQuery(hql, parameters, className + "-->selectByPersonId(long personId)");
	}
	
	public boolean updateSurvey(Survey survey) {
		return super.updateObject(survey, className + "-->updateSurvey(Survey survey)s");
	}
	public boolean deleteSurveyBySurveyId(Long surveyId) {

		String hql = "delete Survey where pid=:surveyId";

		Map<String, Long> parameters = new HashMap<String, Long>(0);
		parameters.put("surveyId", surveyId);

		return super.ExecuteNonQuery(hql, parameters, className + "-->deleteSurveyBySurveyId(Long surveyId)");
	}
	public Survey deleteSurvey(Survey survey) {
		return super.deleteObject(survey, className + "-->deleteSurvey(Survey survey)");
	}
	
}
